package com.numbfish.ch01_ex03_bean_processor.config;

import com.numbfish.ch01_ex03_bean_processor.pojo.Person;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

@Slf4j
public class CustomBeanPostProcessor implements BeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if (bean instanceof Person) {
            log.info("第2步:CustomBeanPostProcessor postProcessBeforeInitialization...bean============={}",bean.getClass().getSimpleName());
        }
        return BeanPostProcessor.super.postProcessBeforeInitialization(bean, beanName);
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (bean instanceof Person) {
            log.info("第5步: CustomBeanPostProcessor postProcessAfterInitialization...bean============={}",bean.getClass().getSimpleName());
        }
        return BeanPostProcessor.super.postProcessAfterInitialization(bean, beanName);
    }
}
